#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector <int>
#define sz(a) ((int) (a).size())
#define me(f, x) memset(f, x, sizeof(f))
#define uint unsigned int
using namespace std;
const int N = 3007, mod = 998244353;

int n, k;
string s;
ll dp[N][N];
int main () {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0); 
	cin >> n >> k;
	cin >> s;
	
	me(dp, 0x3f);
	
	ll ans = 1e18;
	L(i, 0, sz(s) - 1) {
		dp[i][i] = 0;
		if(s[i] == s[i + 1]) {
			dp[i][i + 1] = 0;
		}
	}
	
	L(len, 1, sz(s)) {
		L(l, 0, sz(s) - len) {
			int r = l + len - 1;
			if(s[l] == s[r]) {
				dp[l][r] = min(dp[l][r], dp[l + 1][r - 1]);
				dp[l][r] = min(dp[l][r], dp[l][r - 1] + 1);
				dp[l][r] = min(dp[l][r], dp[l + 1][r] + 1);
//              cout << l << ' ' << r << " : " << dp[l][r] << endl;
			}
		}
	}
	
	L(l, 0, sz(s) - 1) {
		L(r, l, sz(s) - 1) {
			ans = min(ans, max(k - (r - l + 1 + dp[l][r]), 0LL) + dp[l][r]);
		}
	}
	
	cout << ans << '\n';
	return 0;
}
